package com.oxy.listener;

import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.oxy.common.constant.AppConstant;
import com.oxy.common.util.FileUtil;
import com.oxy.util.Oxy;

public class AppInitListener implements ServletContextListener {
	public void contextDestroyed(ServletContextEvent arg) {
	}

	public void contextInitialized(ServletContextEvent arg) {
		// 初始化web.xml中自定义的<context-param>参数并将其放入System中
		ServletContext sc = arg.getServletContext();

		String str = FileUtil.getSafePath(sc.getRealPath("/"));
		System.setProperty(AppConstant.SYS.KEY.REALPATH_ROOT, str);

		str = sc.getContextPath();
		System.setProperty(AppConstant.SYS.KEY.URLPATH_ROOT, str);
		
		// init all system related resources
		Oxy.init();
		
		// 可以通过如下方式获取spring的bean
//		ServletContext context = arg.getServletContext();
//		ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
//		ctx.getBean("testAction");
	}
}
